package com.xexun.gpstracker.util;

import java.io.*;
import java.math.BigDecimal;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.app.Service;
import android.content.*;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.Cursor;
import android.graphics.*;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
import android.location.LocationManager;
import android.media.AudioManager;
import android.media.RingtoneManager;
import android.media.SoundPool;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.ScanResult;
import android.os.*;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.provider.Settings;
import android.telephony.NeighboringCellInfo;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;
import android.util.Base64;
import android.util.Log;
import android.view.*;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONException;

import com.xexun.gpstracker.AppContext;
import com.xexun.gpstracker.channel.R;
import com.xexun.gpstracker.common.Constants;
import com.xexun.gpstracker.inter.CommCallback;
import com.xexun.gpstracker.pojo.ChatMsg;
import com.xexun.gpstracker.pojo.StationInfo;
import com.xexun.gpstracker.vo.Cmd;
import com.xexun.gpstracker.vo.ContType;
import com.xexun.gpstracker.vo.Session;
import com.xexun.gpstracker.vo.WifiAdmin;

public class Utils {
    private static SoundPool pool;
    private static int streamId;
    private static boolean isPlaying = false;
    private static CommCache<String, String> cache = new CommCache<>(true);
    private static Random rand = new Random();
    private static AlertDialog dialog;

    // 获取ApiKey
    public static String getMetaValue(Context context, String metaKey) {
        Bundle metaData = null;
        String apiKey = null;
        if (context == null || metaKey == null) {
            return null;
        }
        try {
            ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
                    context.getPackageName(), PackageManager.GET_META_DATA);
            if (null != ai) {
                metaData = ai.metaData;
            }
            if (null != metaData) {
                apiKey = metaData.getString(metaKey);
            }
        } catch (NameNotFoundException e) {
            //
        }
        return apiKey;
    }

    /**
     * 获取当前时间点
     *
     * @param dateformat
     * @return
     */
    public static String getNowTime(String dateformat) {
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(dateformat);// 可以方便地修改日期格式
        String hehe = dateFormat.format(now);
        return hehe;
    }

    /**
     * 格式化日期 yyyy-MM-dd kk:mm
     *
     * @param date
     * @return
     */
    public static String formatDate(Date date) {
        if (date == null) return "None";
        return android.text.format.DateFormat.format("yyyy-MM-dd kk:mm", date).toString();
    }

    /**
     * 格式化日期 yyyy-MM-dd
     *
     * @param date
     * @return
     */
    public static String formatDateShort(Date date) {
        if (date == null) return "None";
        return android.text.format.DateFormat.format("yyyy-MM-dd", date).toString();
    }

    /**
     * 格式化日期 MM-dd
     *
     * @param date
     * @return
     */
    public static String getMonthDate(Date date) {
        if (date == null) return "None";
        return android.text.format.DateFormat.format("MM-dd", date).toString();
    }

    /**
     * 判断系统是不是24小时制
     *
     * @return boolean  True是24小时
     */
    public static boolean is24(Context ctx) {
        ContentResolver cv = ctx.getContentResolver();
        String strTimeFormat = android.provider.Settings.System.getString(cv, android.provider.Settings.System.TIME_12_24);
        if (strTimeFormat != null && strTimeFormat.equals("24")) {// strTimeFormat某些rom12小时制时会返回null
            return true;
        } else {
            return false;
        }
    }

    /**
     * 比较两个时间的前后关系
     *
     * @param time1 老时间
     * @param time2 新时间
     * @return 0等于，1老时间小于新时间(所需)
     */
    public static int compareTime(String time1, String time2) {
//		String s1="2008-01-25 09:12:09";     
//		String s2="2008-01-29 09:12:11";     
        java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.util.Calendar c1 = java.util.Calendar.getInstance();
        java.util.Calendar c2 = java.util.Calendar.getInstance();
        try {
            c1.setTime(df.parse(time1));
            c2.setTime(df.parse(time2));
        } catch (java.text.ParseException e) {
            Log.e(Constants.TAG, "格式不正确", e);
        }
        int result = c1.compareTo(c2);
        if (result == 0)
            return 0;
//		System.out.println("c1相等c2");     
        else if (result < 0)
            return 1;
//		System.out.println("c1小于c2");     
        else
            return 2;
//		System.out.println("c1大于c2");
    }

    /**
     * 将2014-10-12 12:12:12的格式转换为1012 121212格式
     *
     * @param time
     * @return
     */
    public static String getDayTime(String time) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = df.parse(time);
            SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");// 可以方便地修改日期格式
            String hehe = dateFormat.format(date);
            return hehe;
        } catch (Exception e) {
            Log.e(Constants.TAG, "格式不正确", e);
            return "";
        }
    }

    /**
     * 对网络连接进行判断
     *
     * @return true, 网络已连接； false，未连接网络
     */
    public static boolean isNetworkConnected(Context context) {
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
            if (mNetworkInfo != null) {
                return mNetworkInfo.isAvailable();
            }
        }
        return false;
    }

    /**
     * 对WIFI网络连接进行判断
     *
     * @return true, WIFI已连接； false，WIFI未连接
     */
    public static boolean isWifiConnected(Context context) {
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            if (mWiFiNetworkInfo != null) {
                return mWiFiNetworkInfo.isAvailable();
            }
        }
        return false;
    }

    /**
     * 对MOBILE网络连接进行判断
     *
     * @return true, MOBILE已连接； false，MOBILE未连接
     */
    public static boolean isMobileConnected(Context context) {
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo mMobileNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
            if (mMobileNetworkInfo != null) {
                return mMobileNetworkInfo.isAvailable();
            }
        }
        return false;
    }

    /**
     * 获取网络连接类型
     *
     * @return
     */
    public static int getConnectedType(Context context) {
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
            if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
                return mNetworkInfo.getType();
            }
        }
        return -1;
    }

    /**
     * 创建数据适配器时需要转换的工具
     *
     * @param @return MAP对象
     */
    public static Map<String, Object> createMap(String key, String label, String value) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("key", key);
        map.put("label", label);
        map.put("value", value);
        return map;
    }

    /**
     * 创建键值对工具
     */
    public static Map<String, Object> createMap(String key, String value) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("key", key);
        map.put("value", value);
        return map;
    }

    public static String dataPath = getSDCardPath() + "/gpstracker_data/";

    /**
     * 截取手机屏幕
     */
    private static String SavePath;

    @SuppressWarnings("deprecation")
    public static String GetandSaveCurrentImage(WindowManager windowManager,
                                                View decorview) {
        // 1.构建Bitmap
        Display display = windowManager.getDefaultDisplay();
        int w = display.getWidth();
        int h = display.getHeight();
        Bitmap Bmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);
        // 2.获取屏幕
        decorview.setDrawingCacheEnabled(true);
        Bmp = decorview.getDrawingCache();
        SavePath = getSDCardPath() + "/ShareWX/ScreenImage";
        // 3.保存Bitmap
        try {
            File path = new File(SavePath);
            // 文件
            String filepath = SavePath + "/Scinan_Screen.png";
            File file = new File(filepath);
            if (!path.exists()) {
                path.mkdirs();
            }
            if (!file.exists()) {
                file.createNewFile();
            }

            FileOutputStream fos = null;
            fos = new FileOutputStream(file);
            if (null != fos) {
                Bmp.compress(Bitmap.CompressFormat.PNG, 90, fos);
                fos.flush();
                fos.close();
            }
        } catch (Exception e) {
        }
        return SavePath;
    }

    /**
     * 获取SD卡相关信息
     *
     * @return
     */
    public static String getSDCardPath() {
        File sdcardDir = null;
        // 判断SDCard是否存在
        boolean sdcardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
        if (sdcardExist) {
            sdcardDir = Environment.getExternalStorageDirectory();
        }
        if (sdcardDir == null) {
            return "";
        } else {
            return sdcardDir.toString();
        }
    }

    /**
     * 获取可用存储路径，优先使用SD卡，结尾带斜杠
     *
     * @return
     */
    public static String getAvailableStoragePath() {
        String sdCardPath = getSDCardPath();
        StringBuilder sb = new StringBuilder();
        if (CommUtil.isNotBlank(sdCardPath)) {
            sb.append(sdCardPath).append("/data/").append(AppContext.getContext().getPackageName()).append('/');
        } else {
            sb.append(AppContext.getContext().getFilesDir()).append("/data/");
        }
        return sb.toString();
    }

    /**
     * 生成MD5字符串
     *
     * @param plainText 需要生成MD5的字符串
     * @return MD5字符串
     */
    public static String Md5(String plainText) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes());
            byte b[] = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString().toUpperCase();
//			System.out.println("result: " + buf.toString());// 32位的加密
//			System.out.println("result: " + buf.toString().substring(8, 24));// 16位的加密
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * String类型的集合转换为String 每个数据之间使用“,”间隔
     *
     * @param stringList
     * @return
     */
    public static String listToString(List<String> stringList) {
        if (stringList == null) {
            return null;
        }
        StringBuilder result = new StringBuilder();
        boolean flag = false;
        for (String string : stringList) {
            if (flag) {
                result.append(",");
            } else {
                flag = true;
            }
            result.append(string);
        }
        return result.toString();
    }

    /**
     * 获取WebView使用的HTML代码  没有其他任何修饰的样式
     *
     * @param content 内容
     * @return
     */
    public static String getHtml(String content) {
        StringBuffer html = new StringBuffer();
        html.append("<!DOCTYPE HTML><html><body >");
        html.append(content);
        html.append("</body></html>");
        return html.toString();
    }

    /**
     * 修复图片出线内存溢出的情况
     *
     * @param url  图片的URL
     * @param view 展示的控件
     */
    public static void fixImage(String url, ImageView view) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 2;
        Bitmap b = BitmapFactory.decodeFile(url, options);
        view.setImageBitmap(b);
    }

    /**
     * 动态添加控件
     *
     * @param context
     * @param time
     * @return
     */
    public static TextView getTimeView(Context context, String time) {
        TextView textView = new TextView(context);
        textView.setText(time);
        textView.setTextSize(12);
        textView.setTextColor(0x7f05001e);
        LinearLayout.LayoutParams layoutParams_txt = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams_txt.setMargins(0, 5, 0, 0);
        textView.setLayoutParams(layoutParams_txt);
        return textView;
    }

    /**
     * 验证是否是一个正确的邮箱地址
     *
     * @param email
     * @return
     */
    public static boolean validateEmail(String email) {
        //Pattern pattern = Pattern.compile("[0-9a-zA-Z]*.[0-9a-zA-Z]*@[a-zA-Z]*.[a-zA-Z]*", Pattern.LITERAL);  
        if (email == null) {
            return false;
        }
        //验证开始  
        //不能有连续的.  
        if (email.indexOf("..") != -1) {
            return false;
        }
        //必须带有@  
        int atCharacter = email.indexOf("@");
        if (atCharacter == -1) {
            return false;
        }
        //最后一个.必须在@之后,且不能连续出现  
        if (atCharacter > email.lastIndexOf('.') || atCharacter + 1 == email.lastIndexOf('.')) {
            return false;
        }
        //不能以.,@结束和开始  
        if (email.endsWith(".") || email.endsWith("@") || email.startsWith(".") || email.startsWith("@")) {
            return false;
        }
        return true;
    }

    /**
     * 文本复制
     *
     * @param content 内容
     */
    public static void copy(String content) {
        Context context = AppContext.getContext();
        ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clipData = ClipData.newPlainText(null, content);
        cmb.setPrimaryClip(clipData);
        Toast.makeText(context, R.string.copy_succ, Toast.LENGTH_SHORT).show();
    }

    /**
     * 复制URI到剪贴板
     *
     * @param uri
     */
    public static void copy(Uri uri) {
        Context context = AppContext.getContext();
        ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clipData = ClipData.newUri(context.getContentResolver(), null, uri);
        cmb.setPrimaryClip(clipData);
        Toast.makeText(context, R.string.copy_succ, Toast.LENGTH_SHORT).show();
    }

    /**
     * 粘贴
     *
     * @return
     */
    public static String pasteAsText() {
        Context context = AppContext.getContext();
        ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        if (cmb.getPrimaryClip().getItemCount() == 0) {
            return Constants.DEFAULT_BLANK;
        }
        return cmb.getPrimaryClip().getItemAt(0).coerceToText(context).toString().trim();
    }


    /**
     * 将文件转成base64 字符串
     *
     * @param path 文件路径
     * @return *
     * @throws Exception
     */

    public static String encodeBase64File(String path) {
        try {
            File file = new File(path);
            if (!file.exists()) {
                return "";
            }
            FileInputStream inputFile = new FileInputStream(file);
            byte[] buffer = new byte[(int) file.length()];
            inputFile.read(buffer);
            inputFile.close();
            return new String(Base64.encode(buffer, Base64.DEFAULT));
        } catch (Exception ex) {
            return "";
        }
    }

    /**
     * @param context
     * @return
     */
    public static SharedPreferences getPreferences(Context context) {
        return context.getSharedPreferences("app_info", Context.MODE_PRIVATE);
    }

    /**
     * 获取软键盘管理
     *
     * @param context
     * @return
     */
    public static InputMethodManager getManager(Context context) {
        InputMethodManager manager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        return manager;
    }


    //存储进SD卡
    public static void saveImageFile(Bitmap bm, String fileName) throws Exception {
        File file = new File(fileName);
        //检测图片是否存在
        if (file.exists()) {
            file.delete();  //删除原图片
        }
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, true));
        //100表示不进行压缩，70表示压缩率为30%
        bm.compress(Bitmap.CompressFormat.JPEG, 60, bos);
        bos.flush();
        bos.close();
    }


    /**
     * 根据提供的经度和纬度、以及半径，取得此半径内的最大最小经纬度
     */
    public static double[] getAround(double lat, double lon, int raidus) {

        Double latitude = lat;
        Double longitude = lon;

        Double degree = (24901 * 1609) / 360.0;
        double raidusMile = raidus;

        Double dpmLat = 1 / degree;
        Double radiusLat = dpmLat * raidusMile;
        Double minLat = latitude - radiusLat;
        Double maxLat = latitude + radiusLat;

        Double mpdLng = degree * Math.cos(latitude * (Math.PI / 180));
        Double dpmLng = 1 / mpdLng;
        Double radiusLng = dpmLng * raidusMile;
        Double minLng = longitude - radiusLng;
        Double maxLng = longitude + radiusLng;
        //System.out.println("["+minLat+","+minLng+","+maxLat+","+maxLng+"]");  
        return new double[]{new BigDecimal(minLat).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue(),
                new BigDecimal(minLng).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue(),
                new BigDecimal(maxLat).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue(),
                new BigDecimal(maxLng).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue()};
    }

    /**
     * 获取WIFI相关的信息
     *
     * @param context
     * @return
     */
    public static String getWifiInfo(Context context) {
        WifiAdmin mWifiAdmin = new WifiAdmin(context);
        if (mWifiAdmin.checkState() == 1) {
            return "w,0,";
        } else {
            StringBuffer sb = new StringBuffer();
            // 每次点击扫描之前清空上一次的扫描结果
//    	  	if(sb!=null){
//    	  		sb=new StringBuffer();
//    	  	}
            //开始扫描网络
            mWifiAdmin.startScan();
            List<ScanResult> list = mWifiAdmin.getWifiList();
            if (list != null && list.size() != 0) {
                if (list.size() > 25) {
                    sb.append("w,25,");
                    for (int i = 0; i < 25; i++) {
                        //得到扫描结果
                        ScanResult mScanResult = list.get(i);
                        sb.append((mScanResult.BSSID).replace(":", "") + ",");
                        sb.append((mScanResult.level) + ",");
//        	  			sb=sb.append(+"  ").append(mScanResult.SSID+"   ").append(mScanResult.capabilities+"   ").append(mScanResult.frequency+"   ").append(mScanResult.level+"\n\n");
//        	  			sb=sb.append(mScanResult.BSSID+"  ").append(mScanResult.SSID+"   ").append(mScanResult.capabilities+"   ").append(mScanResult.frequency+"   ").append(mScanResult.level+"\n\n");
                    }
//        	  		allNetWork.setText("扫描到的wifi网络：\n"+sb.toString());
//        	  		System.out.println("扫描到的wifi网络：\n"+sb.toString());
                    return sb.toString();
                } else {
                    sb.append("w," + list.size() + ",");
                    for (int i = 0; i < list.size(); i++) {
                        //得到扫描结果
                        ScanResult mScanResult = list.get(i);
                        sb.append((mScanResult.BSSID).replace(":", "") + ",");
                        sb.append((mScanResult.level) + ",");
//        	  			sb=sb.append(mScanResult.BSSID+"  ").append(mScanResult.SSID+"   ").append(mScanResult.capabilities+"   ").append(mScanResult.frequency+"   ").append(mScanResult.level+"\n\n");
//        	  			sb=sb.append(mScanResult.BSSID+"  ").append(mScanResult.SSID+"   ").append(mScanResult.capabilities+"   ").append(mScanResult.frequency+"   ").append(mScanResult.level+"\n\n");
                    }
//        	  		allNetWork.setText("扫描到的wifi网络：\n"+sb.toString());
//        	  		System.out.println("扫描到的wifi网络：\n"+sb.toString());
                    return sb.toString();
                }
            } else {
                return "w,0,";
            }
        }
    }


    private static Handler handler;

    /**
     * 获取手机基站信息
     *
     * @throws JSONException
     */
    public static String getGSMCellLocationInfo(final Context context) {
        try {
            final List<StationInfo> infoList = new ArrayList<StationInfo>();
            final StationInfo stationInfo = new StationInfo();
//   			int lastSignal=-80;
            TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            manager.listen(new PhoneStateListener() {

                @Override
                public void onSignalStrengthsChanged(SignalStrength signalStrength) {
                    super.onSignalStrengthsChanged(signalStrength);
                    int lastSignal = -113 + 2 * (signalStrength.getGsmSignalStrength()); //信号强度
//					Message message = new Message();
//					message.arg1 = lastSignal;
//					message.what = 0;
//					handler.sendMessage(message);
                    stationInfo.setSignalStrength(lastSignal + "");
//					infoList.add(stationInfo);
//					handler.sendEmptyMessage(0);

//					Toast.makeText(context, "Go to Firstdroid!!! GSM Cinr = " + String.valueOf(lastSignal), Toast.LENGTH_SHORT).show();
                }
            }, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

            handler = new Handler() {
                public void handleMessage(android.os.Message msg) {
                    if (msg.what == 0) {
//   						infoList.add(stationInfo);
//   						int signal = msg.arg1;
//   						stationInfo.setSignalStrength(signal+"");
//   						System.out.println("设置信号强度:"+signal);
                    }
                }

                ;
            };


            String operator = manager.getNetworkOperator();
            if (CommUtil.isBlank(operator)) {
                return Constants.DEFAULT_BLANK;
            }
            /**通过operator获取 MCC 和MNC */
            int mcc = Integer.parseInt(operator.substring(0, 3));
            int mnc = Integer.parseInt(operator.substring(3));
            //	System.out.println("获取基站信息得到的国家代码和信号类型:"+operator+"---mcc:"+mcc+"---mnc:"+mnc);
            if (mnc == 0 || mnc == 1) {
                // 中国移动和中国联通获取LAC、CID的方式
                GsmCellLocation location = (GsmCellLocation) manager.getCellLocation();
                int lac = location.getLac();
                int cellId = (location.getCid()) & 0xffff;
                stationInfo.setCid(cellId + "");
                stationInfo.setLac(lac + "");
                if (stationInfo.getSignalStrength() == null) {
                    stationInfo.setSignalStrength("-" + (int) (Math.random() * 100));
                }
                infoList.add(stationInfo);
                //      System.out.println("获取基站信息得到的基站编号:"+cellId+"----位置区域码:"+lac+"----信号强度:");
            } else if (mnc == 2) {
                /**通过CdmaCellLocation获取中国电信 LAC 和cellID */
                CdmaCellLocation location1 = (CdmaCellLocation) manager.getCellLocation();
                int lac = location1.getNetworkId();
                int cellId = location1.getBaseStationId() / 16;
                stationInfo.setCid(cellId + "");
                stationInfo.setLac(lac + "");
                if (stationInfo.getSignalStrength() == null) {
                    stationInfo.setSignalStrength("-" + (int) (Math.random() * 100));
                }
                infoList.add(stationInfo);
                //    System.out.println("获取基站信息得到的基站编号:"+cellId+"----位置区域码:"+lac+"----信号强度:");
            }


//   			GsmCellLocation location = (GsmCellLocation) manager.getCellLocation();
            /**通过GsmCellLocation获取中国移动和联通 LAC 和cellID */
//   			int lac = location.getLac();
//   			int cellid = location.getCid();
//   			System.out.println("基站ID："+cellid);
            /**通过CdmaCellLocation获取中国电信 LAC 和cellID */
//   	       CdmaCellLocation location1 = (CdmaCellLocation) mTelephonyManager.getCellLocation(); 
//   	       lac = location1.getNetworkId(); 
//   	      cellId = location1.getBaseStationId(); 
//   	      cellId /= 16;
//   			int strength = 0;
//   			/**通过getNeighboringCellInfo获取BSSS */
//   			List<NeighboringCellInfo> infoLists = manager.getNeighboringCellInfo();
//   			System.out.println("infoLists:"+infoLists+"     size:"+infoLists.size());
//   			for (NeighboringCellInfo info : infoLists) {
//   				strength+=(-133+2*info.getRssi());// 获取邻区基站信号强度 
//   				info.getLac();// 取出当前邻区的LAC 
//   				info.getCid();// 取出当前邻区的CID 
//   				System.out.println("信号强度rssi:"+info.getRssi()+"   strength:"+strength+"-=-=-=基站ID:"+info.getCid());
//   			}
            // 获取邻区基站信息
            List<NeighboringCellInfo> infos = manager.getNeighboringCellInfo();
            StringBuffer sb = new StringBuffer("总数 : " + infos.size() + "\n");
            if (infos.size() >= 6) {
                for (int i = 0; i < 6; i++) {
                    StationInfo stationInfo1 = new StationInfo();
                    stationInfo1.setSignalStrength((-113 + 2 * infos.get(i).getRssi()) + "");
                    stationInfo1.setCid(infos.get(i).getCid() + "");
                    stationInfo1.setLac(infos.get(i).getLac() + "");
                    infoList.add(stationInfo1);
                }
            } else {
                for (NeighboringCellInfo info1 : infos) { // 根据邻区总数进行循环
                    sb.append(" 邻区的LAC : " + info1.getLac()); // 取出当前邻区的LAC
                    sb.append(" 邻区的CID : " + info1.getCid()); // 取出当前邻区的CID
                    sb.append(" 邻区基站信号强度BSSS : " + (-113 + 2 * info1.getRssi()) + "\n"); // 获取邻区基站信号强度
                    StationInfo stationInfo1 = new StationInfo();
                    stationInfo1.setSignalStrength((-113 + 2 * info1.getRssi()) + "");
                    stationInfo1.setCid(info1.getCid() + "");
                    stationInfo1.setLac(info1.getLac() + "");
                    infoList.add(stationInfo1);
                }
            }
            // System.out.println("获取邻区基站信息:" + sb.toString());
            StringBuffer sbTemp = new StringBuffer();
            sbTemp.append("l," + infoList.size() + "," + mcc + "," + mnc + ",");
            for (int i = 0; i < infoList.size(); i++) {
                sbTemp.append(infoList.get(i).getCid() + "," + infoList.get(i).getLac() + "," + infoList.get(i).getSignalStrength() + ",");
            }
            return sbTemp.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    /**
     * 把一个View的对象转换成bitmap
     */
    public static Bitmap getViewBitmap(View view) {
        view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
        view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
        view.buildDrawingCache();
        return view.getDrawingCache();
    }

    /**
     * 判断电话号码格式
     * 一键呼叫，拨打911，110，国内外手机号，座机
     *
     * @param mobile
     * @return
     */
    public static boolean isMobileNO(String mobile) {
        return CommUtil.isNotBlank(mobile) && mobile.matches(Constants.MOBILE_FMT_I18N);
    }

    public static boolean isChinaMobileNO(String mobile) {
        return CommUtil.isNotBlank(mobile) && mobile.matches(Constants.MOBILE_FMT_CHINA);
    }

    // 判断email格式是否正确
    public static boolean isEmail(String email) {
        String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
        Pattern p = Pattern.compile(str);
        Matcher m = p.matcher(email);

        return m.matches();
    }

    public static String join(String join, List<String> strAry) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < strAry.size(); i++) {
            if (i == (strAry.size() - 1)) {
                sb.append(strAry.get(i));
            } else {
                sb.append(strAry.get(i)).append(join);
            }
        }

        return new String(sb);
    }

    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     */
    public static int dp2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
     */
    public static int px2dp(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

    /**
     * 手机震动
     *
     * @param activity
     * @param milliseconds
     */
    public static void Vibrate(final Activity activity, long milliseconds) {
        Vibrator vib = (Vibrator) activity.getSystemService(Service.VIBRATOR_SERVICE);
        vib.vibrate(milliseconds);
    }

    /**
     * final Context context  ：调用该方法的Activity实例
     * long milliseconds ：震动的时长，单位是毫秒
     * long[] pattern  ：自定义震动模式 。数组中数字的含义依次是[静止时长，震动时长，静止时长，震动时长。。。]时长的单位是毫秒
     * boolean isRepeat ： 是否反复震动，如果是true，反复震动，如果是false，只震动一次
     * boolean flag:为true时震动，为false时不震动
     */
    public static void Vibrate(final Context context, long[] pattern, boolean isRepeat, boolean flag) {
        //zwd注释震动
//        if (flag) {
//            Vibrator vib = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);
//            vib.vibrate(pattern, isRepeat ? 1 : -1);
//        }
    }

    /**
     * 震动关闭
     *
     * @param context
     */
    public static void closeVibrate(Context context) {
        //zwd注释震动
//        Vibrator vib = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);
//        vib.cancel();
    }

    /**
     * 图片转灰度
     *
     * @param bmpOriginal
     * @return
     */
    public static Bitmap toGrayscale(Bitmap bmpOriginal) {
        int width, height;
        height = bmpOriginal.getHeight();
        width = bmpOriginal.getWidth();

        Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        Canvas c = new Canvas(bmpGrayscale);
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
        paint.setColorFilter(f);
        c.drawBitmap(bmpOriginal, 0, 0, paint);
        return bmpGrayscale;
    }

    /**
     * 将ImageView的图片转为灰色，ImageView必须是有图片的情况下才能用
     *
     * @param view
     */
    public static void setGrayImageView(ImageView view) {
        view.buildDrawingCache();
        BitmapDrawable drawable = (BitmapDrawable) view.getDrawable();
        if (null != drawable) {
            Bitmap image = drawable.getBitmap();
            if (null != image) {
                Bitmap bitmap = toGrayscale(image);
                view.setImageBitmap(bitmap);
            }
        }
    }

    public static Bitmap getBitmapFromView(ImageView view) {
        view.buildDrawingCache();
        BitmapDrawable drawable = (BitmapDrawable) view.getDrawable();
        if (null != drawable) {
            Bitmap image = drawable.getBitmap();
            return image;
        }
        return null;
    }

    public static byte[] bitmap2Bytes(Bitmap bm) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
        return baos.toByteArray();
    }

    public static Bitmap bytes2Bimap(byte[] b) {
        if (b.length != 0) {
            return BitmapFactory.decodeByteArray(b, 0, b.length);
        } else {
            return null;
        }
    }

    /**
     * 强制帮用户打开GPS
     *
     * @param context
     */
    public static void openGPS(Context context) {
        Intent GPSIntent = new Intent();
        GPSIntent.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
        GPSIntent.addCategory("android.intent.category.ALTERNATIVE");
        GPSIntent.setData(Uri.parse("custom:3"));
        try {
            PendingIntent.getBroadcast(context, 0, GPSIntent, 0).send();
        } catch (PendingIntent.CanceledException e) {
            e.printStackTrace();
        }
    }

    public static void openGPSManually(Context context) {
        LocationManager alm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        if (alm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            Toast.makeText(context, "GPS模块正常", Toast.LENGTH_SHORT).show();
        }
        Toast.makeText(context, "请开启GPS！", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        context.startActivity(intent);
    }

    public static String getPrettyDescribe(Context context, ContType type, String content, int maxChar) {
        String cont = Constants.DEFAULT_BLANK;
        if (ContType.SOS_ALERT != type && ((ContType.isTxtType(type) && CommUtil.isBlank(content)) || maxChar < 1)) {
            return cont;
        }
        if (ContType.TXT == type) {
            cont = content.length() > (maxChar + 3) ? content.substring(0, maxChar - 3) + "..." : content;
            if (cont.startsWith("[zgif")) {
                cont = context.getString(R.string.msg_face);
            }
        } else if (ContType.PIC == type) {
            cont = context.getString(R.string.msg_pic);
        } else if (ContType.AUDIO == type) {
            cont = context.getString(R.string.msg_audio);
        } else if (ContType.VIDEO == type) {
            cont = context.getString(R.string.msg_video);
        } else if (ContType.FILE == type) {
            cont = context.getString(R.string.msg_file);
        } else if (ContType.SOS_ALERT == type) {
            cont = CommUtil.isNotBlank(content) ? content : context.getString(R.string.msg_posi);
        } else if (ContType.isTxtType(type)) {
            cont = content.length() > (maxChar + 3) ? content.substring(0, maxChar - 3) + "..." : content;
        } else {
            cont = context.getString(R.string.msg_unkonow);
        }
        return cont;
    }

    public static String getBaseUrl(Context context) {
        String baseUrl;
        SharedPreferences mSharedPreferences = getPreferences(context);
        baseUrl = mSharedPreferences.getString(Constants.SETTING_SERVER_URL, null);
        if (CommUtil.isBlank(baseUrl) || baseUrl.length() < 8) {
            baseUrl = getBaseUrlFromMeta(context);
        }
        return baseUrl;
    }

    public static String getBaseUrlFromMeta(Context context) {
//        String domain = getMetaValue(context, Constants.IS_CHINA_VERSION ? "domain" : "domain_en");
        String domain = getMetaValue(context,"domain" );
        String baseUrl = getMetaValue(context, "base_url");
        if (CommUtil.isNotBlank(baseUrl) && CommUtil.isNotBlank(domain)) {
            return baseUrl.replaceAll("\\{domain\\}", domain);
        }
        return null;
    }

    /**
     * Get a file path from a Uri. This will get the the path for Storage Access
     * Framework Documents, as well as the _data field for the MediaStore and
     * other file-based ContentProviders.
     *
     * @param context The context.
     * @param uri     The Uri to query.
     * @author paulburke
     */
    @TargetApi(Build.VERSION_CODES.KITKAT)
    public static String getRealFilePath(final Context context, final Uri uri) {
        final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
        // DocumentProvider
        if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
            // ExternalStorageProvider
            if (isExternalStorageDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                if ("primary".equalsIgnoreCase(type)) {
                    return Environment.getExternalStorageDirectory() + "/" + split[1];
                }
            }
            // DownloadsProvider
            else if (isDownloadsDocument(uri)) {

                final String id = DocumentsContract.getDocumentId(uri);
                final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
                return getDataColumn(context, contentUri, null, null);
            }
            // MediaProvider
            else if (isMediaDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                Uri contentUri = null;
                if ("image".equals(type)) {
                    contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video".equals(type)) {
                    contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(type)) {
                    contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }
                final String selection = "_id=?";
                final String[] selectionArgs = new String[]{split[1]};
                return getDataColumn(context, contentUri, selection, selectionArgs);
            }
        }
        // MediaStore (and general)
        else if (ContentResolver.SCHEME_CONTENT.equalsIgnoreCase(uri.getScheme())) {
            return getDataColumn(context, uri, null, null);
        }
        // File
//        else if (ContentResolver.SCHEME_FILE.equalsIgnoreCase(uri.getScheme())){
        else {
            return uri.getPath();
        }
        return null;
    }

    /**
     * Get the value of the data column for this Uri. This is useful for
     * MediaStore Uris, and other file-based ContentProviders.
     *
     * @param context       The context.
     * @param uri           The Uri to query.
     * @param selection     (Optional) Filter used in the query.
     * @param selectionArgs (Optional) Selection arguments used in the query.
     * @return The value of the _data column, which is typically a file path.
     */
    public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
        Cursor cursor = null;
        final String column = MediaStore.MediaColumns.DATA;
        final String[] projection = {column};
        try {
            cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
            if (cursor != null && cursor.moveToFirst()) {
                final int column_index = cursor.getColumnIndexOrThrow(column);
                return cursor.getString(column_index);
            }
        } finally {
            if (cursor != null)
                cursor.close();
        }
        return null;
    }


    /**
     * @param uri The Uri to check.
     * @return Whether the Uri authority is ExternalStorageProvider.
     */
    private static boolean isExternalStorageDocument(Uri uri) {
        return "com.android.externalstorage.documents".equals(uri.getAuthority());
    }

    /**
     * @param uri The Uri to check.
     * @return Whether the Uri authority is DownloadsProvider.
     */
    private static boolean isDownloadsDocument(Uri uri) {
        return "com.android.providers.downloads.documents".equals(uri.getAuthority());
    }

    /**
     * @param uri The Uri to check.
     * @return Whether the Uri authority is MediaProvider.
     */
    private static boolean isMediaDocument(Uri uri) {
        return "com.android.providers.media.documents".equals(uri.getAuthority());
    }

    /**
     * 播放指定uri的声音
     *
     * @param context
     * @param uri
     */
    public synchronized static void playShortSound(Context context, Uri uri) {
        try {
            if (pool == null) {
                pool = new SoundPool(1, AudioManager.STREAM_RING, 0);
            }
            if (!isPlaying) {
                isPlaying = true;
                if (Constants.SCHEME_ASSETS.startsWith(uri.getScheme())) {
                    pool.load(context.getAssets().openFd(uri.getHost()), 0);
                } else if (Constants.SCHEME_RES.startsWith(uri.getScheme())) {
                    pool.load(context, Integer.valueOf(uri.getHost()), 0);
                } else {
                    pool.load(getRealFilePath(context, uri), 0);
                }
                pool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
                    @Override
                    public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                        streamId = soundPool.play(sampleId, 1, 1, 0, 0, 1);
                        isPlaying = false;
                    }
                });
            }
        } catch (Exception e) {
            Log.w(Constants.TAG, "播放声音失败", e);
        }
    }

    public static void stopSound() {
        if (pool != null) {
            pool.stop(streamId);
        }
    }

    /**
     * 获取电池电量百分比
     *
     * @param ele
     * @return
     */
//    public static int getElectricityPercent(double ele) {
//
//        if(ele > 30000){
//            ele = ele * 0.0001;
//        }else if(ele > 300){
//            ele = ele *0.01;
//        }
//        if(ele < Constants.VOLTAGE_LOWER){
//            if(ele <= 1 && ele > 0){
//                return (int)(ele * 100 +0.5);
//            }
//            return  0;
//        }else if (ele > Constants.VOLTAGE_UPPER ){
//            return 100;
//        }else {
//            return (int)((ele - Constants.VOLTAGE_LOWER)/(Constants.VOLTAGE_UPPER - Constants.VOLTAGE_LOWER) * 100 +0.5);
//        }
//
////        if (ele >= 0 && ele <= 1) {
////            //兼容最新电量百分比显示
////            return (int) (ele * 100 + 0.5);
////        }
////        if (ele >= Constants.VOLTAGE_UPPER) {
////            return 100;
////        } else if (ele <= Constants.VOLTAGE_LOWER) {
////            return 0;
////        } else {
////            return (int) (((ele - Constants.VOLTAGE_LOWER) / (Constants.VOLTAGE_UPPER - Constants.VOLTAGE_LOWER)) * 100 + 0.5);
////        }
//    }


    private static  final double FULL =  41189;
    private static  final double EMPTY   =  35996;


    public static double getElectricityPercent(double ele){

    double data[][] = {
            {41189,99.99999999},
            {41170,99.63412286},
            {41155,99.34527248},
            {41136,98.97939534},
            {41121,98.69054496},
            {41108,98.44020797},
            {41090,98.09358752},
            {41077,97.84325053},
            {41062,97.55440015},
            {41049,97.30406316},
            {41034,97.01521279},
            {41021,96.76487579},
            {41009,96.53379549},
            {40997,96.30271519},
            {40984,96.0523782},
            {40975,95.87906798},
            {40962,95.62873098},
            {40953,95.45542076},
            {40941,95.22434046},
            {40931,95.03177354},
            {40919,94.80069324},
            {40910,94.62738302},
            {40900,94.4348161},
            {40891,94.26150587},
            {40879,94.03042557},
            {40869,93.83785866},
            {40860,93.66454843},
            {40851,93.49123821},
            {40842,93.31792798},
            {40832,93.12536106},
            {40823,92.95205084},
            {40811,92.72097054},
            {40801,92.52840362},
            {40792,92.35509339},
            {40783,92.18178317},
            {40773,91.98921625},
            {40764,91.81590603},
            {40755,91.6425958},
            {40749,91.52705565},
            {40739,91.33448873},
            {40730,91.16117851},
            {40721,90.98786828},
            {40711,90.79530137},
            {40702,90.62199114},
            {40693,90.44868092},
            {40687,90.33314077},
            {40677,90.14057385},
            {40671,90.0250337},
            {40659,89.7939534},
            {40649,89.60138648},
            {40643,89.48584633},
            {40634,89.31253611},
            {40628,89.19699596},
            {40618,89.00442904},
            {40609,88.83111881},
            {40600,88.65780859},
            {40593,88.52301175},
            {40581,88.29193145},
            {40575,88.1763913},
            {40566,88.00308107},
            {40556,87.81051415},
            {40547,87.63720393},
            {40541,87.52166378},
            {40535,87.40612363},
            {40525,87.21355671},
            {40516,87.04024649},
            {40507,86.86693626},
            {40497,86.67436934},
            {40491,86.55882919},
            {40485,86.44328904},
            {40476,86.26997882},
            {40469,86.13518198},
            {40460,85.96187175},
            {40451,85.78856153},
            {40445,85.67302137},
            {40435,85.48045446},
            {40429,85.36491431},
            {40420,85.19160408},
            {40411,85.01829386},
            {40404,84.88349702},
            {40398,84.76795687},
            {40389,84.59464664},
            {40383,84.47910649},
            {40373,84.28653957},
            {40364,84.11322935},
            {40355,83.93991912},
            {40345,83.7473522},
            {40339,83.63181205},
            {40333,83.5162719},
            {40324,83.34296168},
            {40314,83.15039476},
            {40305,82.97708454},
            {40299,82.86154439},
            {40293,82.74600424},
            {40283,82.55343732},
            {40277,82.43789717},
            {40268,82.26458694},
            {40262,82.14904679},
            {40252,81.95647988},
            {40246,81.84093973},
            {40237,81.6676295},
            {40231,81.55208935},
            {40221,81.35952243},
            {40215,81.24398228},
            {40209,81.12844213},
            {40200,80.95513191},
            {40190,80.76256499},
            {40184,80.64702484},
            {40175,80.47371462},
            {40169,80.35817447},
            {40159,80.16560755},
            {40153,80.0500674},
            {40147,79.93452725},
            {40141,79.8189871},
            {40128,79.56865011},
            {40119,79.39533988},
            {40113,79.27979973},
            {40107,79.16425958},
            {40101,79.04871943},
            {40091,78.85615251},
            {40082,78.68284229},
            {40076,78.56730214},
            {40070,78.45176199},
            {40063,78.31696515},
            {40054,78.14365492},
            {40048,78.02811477},
            {40039,77.85480454},
            {40032,77.7200077},
            {40026,77.60446755},
            {40020,77.4889274},
            {40014,77.37338725},
            {40004,77.18082034},
            {39995,77.00751011},
            {39989,76.89196996},
            {39983,76.77642981},
            {39977,76.66088966},
            {39970,76.52609282},
            {39964,76.41055267},
            {39955,76.23724244},
            {39949,76.12170229},
            {39942,75.98690545},
            {39936,75.8713653},
            {39927,75.69805507},
            {39921,75.58251492},
            {39915,75.46697477},
            {39905,75.27440786},
            {39899,75.15886771},
            {39893,75.04332756},
            {39887,74.92778741},
            {39877,74.73522049},
            {39871,74.61968034},
            {39865,74.50414019},
            {39856,74.33082996},
            {39853,74.27305989},
            {39843,74.08049297},
            {39837,73.96495282},
            {39831,73.84941267},
            {39825,73.73387252},
            {39818,73.59907568},
            {39812,73.48353553},
            {39806,73.36799538},
            {39800,73.25245523},
            {39791,73.079145},
            {39784,72.94434816},
            {39778,72.82880801},
            {39772,72.71326786},
            {39766,72.59772771},
            {39760,72.48218756},
            {39753,72.34739072},
            {39744,72.17408049},
            {39738,72.05854034},
            {39732,71.94300019},
            {39725,71.80820335},
            {39719,71.6926632},
            {39713,71.57712305},
            {39707,71.4615829},
            {39701,71.34604275},
            {39694,71.21124591},
            {39685,71.03793568},
            {39676,70.86462546},
            {39667,70.69131523},
            {39663,70.61428847},
            {39657,70.49874832},
            {39648,70.32543809},
            {39642,70.20989794},
            {39636,70.09435779},
            {39626,69.90179087},
            {39623,69.8440208},
            {39614,69.67071057},
            {39608,69.55517042},
            {39601,69.42037358},
            {39595,69.30483343},
            {39586,69.1315232},
            {39580,69.01598305},
            {39574,68.9004429},
            {39567,68.76564606},
            {39561,68.65010591},
            {39555,68.53456576},
            {39546,68.36125554},
            {39539,68.22645869},
            {39533,68.11091854},
            {39524,67.93760832},
            {39518,67.82206817},
            {39512,67.70652802},
            {39505,67.57173118},
            {39496,67.39842095},
            {39490,67.2828808},
            {39484,67.16734065},
            {39477,67.03254381},
            {39471,66.91700366},
            {39462,66.74369343},
            {39453,66.57038321},
            {39446,66.43558637},
            {39440,66.32004622},
            {39434,66.20450607},
            {39428,66.08896592},
            {39415,65.83862892},
            {39409,65.72308877},
            {39403,65.60754862},
            {39397,65.49200847},
            {39391,65.37646832},
            {39384,65.24167148},
            {39375,65.06836126},
            {39369,64.95282111},
            {39363,64.83728096},
            {39357,64.7217408},
            {39350,64.58694396},
            {39344,64.47140381},
            {39335,64.29809359},
            {39329,64.18255344},
            {39322,64.0477566},
            {39316,63.93221645},
            {39310,63.8166763},
            {39304,63.70113614},
            {39298,63.58559599},
            {39291,63.45079915},
            {39285,63.335259},
            {39279,63.21971885},
            {39273,63.1041787},
            {39267,62.98863855},
            {39257,62.79607163},
            {39251,62.68053148},
            {39245,62.56499133},
            {39239,62.44945118},
            {39233,62.33391103},
            {39223,62.14134412},
            {39217,62.02580397},
            {39211,61.91026382},
            {39205,61.79472367},
            {39198,61.65992682},
            {39192,61.54438667},
            {39186,61.42884652},
            {39177,61.2555363},
            {39171,61.13999615},
            {39167,61.06296938},
            {39161,60.94742923},
            {39155,60.83188908},
            {39149,60.71634893},
            {39143,60.60080878},
            {39136,60.46601194},
            {39130,60.35047179},
            {39124,60.23493164},
            {39118,60.11939149},
            {39112,60.00385134},
            {39105,59.8690545},
            {39099,59.75351435},
            {39093,59.6379742},
            {39087,59.52243405},
            {39081,59.4068939},
            {39078,59.34912382},
            {39071,59.21432698},
            {39065,59.09878683},
            {39059,58.98324668},
            {39053,58.86770653},
            {39046,58.73290969},
            {39040,58.61736954},
            {39034,58.50182939},
            {39028,58.38628924},
            {39022,58.27074909},
            {39015,58.13595224},
            {39009,58.02041209},
            {39006,57.96264202},
            {38994,57.73156172},
            {38988,57.61602157},
            {38981,57.48122473},
            {38978,57.42345465},
            {38972,57.3079145},
            {38966,57.19237435},
            {38963,57.13460427},
            {38953,56.94203736},
            {38950,56.88426728},
            {38944,56.76872713},
            {38938,56.65318698},
            {38932,56.53764683},
            {38926,56.42210668},
            {38919,56.28730984},
            {38913,56.17176969},
            {38910,56.11399961},
            {38904,55.99845946},
            {38898,55.88291931},
            {38891,55.74812247},
            {38885,55.63258232},
            {38879,55.51704217},
            {38876,55.4592721},
            {38870,55.34373195},
            {38864,55.2281918},
            {38857,55.09339495},
            {38851,54.9778548},
            {38845,54.86231465},
            {38842,54.80454458},
            {38836,54.68900443},
            {38829,54.55420759},
            {38823,54.43866744},
            {38817,54.32312729},
            {38814,54.26535721},
            {38808,54.14981706},
            {38802,54.03427691},
            {38795,53.89948007},
            {38789,53.78393992},
            {38783,53.66839977},
            {38774,53.49508954},
            {38771,53.43731947},
            {38764,53.30252263},
            {38761,53.24475255},
            {38752,53.07144233},
            {38749,53.01367225},
            {38743,52.8981321},
            {38736,52.76333526},
            {38730,52.64779511},
            {38727,52.59002503},
            {38718,52.41671481},
            {38715,52.35894473},
            {38709,52.24340458},
            {38705,52.16637782},
            {38699,52.05083767},
            {38693,51.93529752},
            {38687,51.81975737},
            {38681,51.70421722},
            {38674,51.56942037},
            {38671,51.5116503},
            {38665,51.39611015},
            {38662,51.33834007},
            {38653,51.16502985},
            {38650,51.10725977},
            {38643,50.97246293},
            {38637,50.85692278},
            {38634,50.79915271},
            {38628,50.68361256},
            {38622,50.56807241},
            {38616,50.45253225},
            {38612,50.37550549},
            {38606,50.25996534},
            {38600,50.14442519},
            {38597,50.08665511},
            {38588,49.91334489},
            {38585,49.85557481},
            {38578,49.72077797},
            {38575,49.6630079},
            {38569,49.54746775},
            {38563,49.43192759},
            {38557,49.31638744},
            {38547,49.12382053},
            {38544,49.06605045},
            {38538,48.9505103},
            {38532,48.83497015},
            {38529,48.77720008},
            {38523,48.66165993},
            {38516,48.52686308},
            {38510,48.41132293},
            {38507,48.35355286},
            {38501,48.23801271},
            {38498,48.18024263},
            {38492,48.06470248},
            {38485,47.92990564},
            {38479,47.81436549},
            {38476,47.75659542},
            {38470,47.64105527},
            {38467,47.58328519},
            {38461,47.46774504},
            {38454,47.3329482},
            {38448,47.21740805},
            {38445,47.15963797},
            {38439,47.04409782},
            {38436,46.98632775},
            {38430,46.8707876},
            {38423,46.73599076},
            {38417,46.62045061},
            {38414,46.56268053},
            {38411,46.50491046},
            {38405,46.38937031},
            {38399,46.27383016},
            {38395,46.19680339},
            {38389,46.08126324},
            {38386,46.02349316},
            {38380,45.90795301},
            {38377,45.85018294},
            {38371,45.73464279},
            {38364,45.59984595},
            {38361,45.54207587},
            {38355,45.42653572},
            {38352,45.36876565},
            {38349,45.31099557},
            {38343,45.19545542},
            {38337,45.07991527},
            {38330,44.94511843},
            {38327,44.88734835},
            {38321,44.7718082},
            {38315,44.65626805},
            {38309,44.5407279},
            {38306,44.48295783},
            {38299,44.34816099},
            {38296,44.29039091},
            {38290,44.17485076},
            {38287,44.11708069},
            {38281,44.00154054},
            {38278,43.94377046},
            {38271,43.80897362},
            {38268,43.75120354},
            {38265,43.69343347},
            {38259,43.57789332},
            {38253,43.46235317},
            {38250,43.40458309},
            {38247,43.34681302},
            {38240,43.21201618},
            {38237,43.1542461},
            {38231,43.03870595},
            {38228,42.98093588},
            {38222,42.86539573},
            {38219,42.80762565},
            {38216,42.74985557},
            {38209,42.61505873},
            {38206,42.55728866},
            {38200,42.44174851},
            {38197,42.38397843},
            {38191,42.26843828},
            {38188,42.21066821},
            {38182,42.09512806},
            {38178,42.01810129},
            {38172,41.90256114},
            {38169,41.84479106},
            {38166,41.78702099},
            {38160,41.67148084},
            {38157,41.61371076},
            {38154,41.55594069},
            {38147,41.42114385},
            {38141,41.3056037},
            {38138,41.24783362},
            {38135,41.19006355},
            {38129,41.0745234},
            {38126,41.01675332},
            {38120,40.90121317},
            {38116,40.8241864},
            {38110,40.70864625},
            {38107,40.65087618},
            {38104,40.5931061},
            {38095,40.41979588},
            {38089,40.30425573},
            {38085,40.22722896},
            {38082,40.16945889},
            {38076,40.05391874},
            {38073,39.99614866},
            {38070,39.93837859},
            {38064,39.82283844},
            {38061,39.76506836},
            {38058,39.70729829},
            {38051,39.57250144},
            {38048,39.51473137},
            {38045,39.45696129},
            {38039,39.34142114},
            {38036,39.28365107},
            {38030,39.16811092},
            {38027,39.11034084},
            {38023,39.03331408},
            {38020,38.975544},
            {38014,38.86000385},
            {38008,38.7444637},
            {38008,38.7444637},
            {38002,38.62892355},
            {37999,38.57115348},
            {37992,38.43635663},
            {37989,38.37858656},
            {37983,38.26304641},
            {37980,38.20527633},
            {37977,38.14750626},
            {37974,38.08973618},
            {37968,37.97419603},
            {37965,37.91642596},
            {37958,37.78162912},
            {37955,37.72385904},
            {37952,37.66608897},
            {37946,37.55054882},
            {37946,37.55054882},
            {37940,37.43500867},
            {37937,37.37723859},
            {37930,37.24244175},
            {37927,37.18467167},
            {37924,37.1269016},
            {37918,37.01136145},
            {37915,36.95359137},
            {37909,36.83805122},
            {37906,36.78028115},
            {37903,36.72251107},
            {37899,36.64548431},
            {37893,36.52994416},
            {37890,36.47217408},
            {37887,36.41440401},
            {37881,36.29886386},
            {37878,36.24109378},
            {37875,36.1833237},
            {37868,36.04852686},
            {37862,35.93298671},
            {37859,35.87521664},
            {37856,35.81744656},
            {37850,35.70190641},
            {37847,35.64413634},
            {37844,35.58636626},
            {37841,35.52859619},
            {37834,35.39379935},
            {37831,35.33602927},
            {37828,35.2782592},
            {37825,35.22048912},
            {37819,35.10494897},
            {37816,35.04717889},
            {37813,34.98940882},
            {37806,34.85461198},
            {37803,34.7968419},
            {37800,34.73907183},
            {37794,34.62353168},
            {37794,34.62353168},
            {37788,34.50799153},
            {37782,34.39245138},
            {37782,34.39245138},
            {37775,34.25765453},
            {37772,34.19988446},
            {37769,34.14211438},
            {37763,34.02657423},
            {37760,33.96880416},
            {37757,33.91103408},
            {37754,33.85326401},
            {37751,33.79549393},
            {37744,33.66069709},
            {37741,33.60292702},
            {37738,33.54515694},
            {37732,33.42961679},
            {37729,33.37184672},
            {37726,33.31407664},
            {37723,33.25630657},
            {37720,33.19853649},
            {37713,33.06373965},
            {37710,33.00596957},
            {37707,32.9481995},
            {37704,32.89042942},
            {37701,32.83265935},
            {37695,32.7171192},
            {37692,32.65934912},
            {37689,32.60157905},
            {37686,32.54380897},
            {37682,32.46678221},
            {37676,32.35124206},
            {37673,32.29347198},
            {37670,32.23570191},
            {37667,32.17793183},
            {37664,32.12016176},
            {37658,32.00462161},
            {37658,32.00462161},
            {37651,31.86982476},
            {37648,31.81205469},
            {37642,31.69651454},
            {37639,31.63874446},
            {37636,31.58097439},
            {37630,31.46543424},
            {37627,31.40766416},
            {37624,31.34989409},
            {37620,31.27286732},
            {37617,31.21509725},
            {37614,31.15732717},
            {37611,31.0995571},
            {37608,31.04178702},
            {37605,30.98401695},
            {37599,30.8684768},
            {37596,30.81070672},
            {37593,30.75293665},
            {37589,30.67590988},
            {37586,30.6181398},
            {37583,30.56036973},
            {37580,30.50259965},
            {37577,30.44482958},
            {37574,30.3870595},
            {37568,30.27151935},
            {37565,30.21374928},
            {37562,30.1559792},
            {37562,30.1559792},
            {37555,30.02118236},
            {37552,29.96341229},
            {37549,29.90564221},
            {37546,29.84787214},
            {37543,29.79010206},
            {37537,29.67456191},
            {37537,29.67456191},
            {37531,29.55902176},
            {37527,29.48199499},
            {37524,29.42422492},
            {37521,29.36645484},
            {37518,29.30868477},
            {37515,29.25091469},
            {37512,29.19314462},
            {37506,29.07760447},
            {37506,29.07760447},
            {37503,29.01983439},
            {37496,28.88503755},
            {37493,28.82726748},
            {37490,28.7694974},
            {37487,28.71172733},
            {37484,28.65395725},
            {37481,28.59618718},
            {37478,28.5384171},
            {37475,28.48064702},
            {37472,28.42287695},
            {37468,28.34585018},
            {37465,28.28808011},
            {37462,28.23031003},
            {37459,28.17253996},
            {37456,28.11476988},
            {37450,27.99922973},
            {37447,27.94145966},
            {37444,27.88368958},
            {37441,27.82591951},
            {37437,27.74889274},
            {37434,27.69112267},
            {37431,27.63335259},
            {37428,27.57558251},
            {37425,27.51781244},
            {37422,27.46004236},
            {37416,27.34450221},
            {37413,27.28673214},
            {37410,27.22896206},
            {37406,27.1519353},
            {37403,27.09416522},
            {37400,27.03639515},
            {37397,26.97862507},
            {37394,26.920855},
            {37391,26.86308492},
            {37388,26.80531485},
            {37385,26.74754477},
            {37382,26.6897747},
            {37379,26.63200462},
            {37372,26.49720778},
            {37372,26.49720778},
            {37369,26.4394377},
            {37366,26.38166763},
            {37360,26.26612748},
            {37360,26.26612748},
            {37357,26.2083574},
            {37354,26.15058733},
            {37348,26.03504718},
            {37344,25.95802041},
            {37341,25.90025034},
            {37341,25.90025034},
            {37338,25.84248026},
            {37335,25.78471019},
            {37329,25.66917004},
            {37329,25.66917004},
            {37323,25.55362989},
            {37323,25.55362989},
            {37320,25.49585981},
            {37317,25.43808974},
            {37310,25.30329289},
            {37310,25.30329289},
            {37304,25.18775274},
            {37304,25.18775274},
            {37301,25.12998267},
            {37298,25.07221259},
            {37295,25.01444252},
            {37292,24.95667244},
            {37286,24.84113229},
            {37286,24.84113229},
            {37282,24.76410553},
            {37279,24.70633545},
            {37276,24.64856538},
            {37273,24.5907953},
            {37270,24.53302523},
            {37267,24.47525515},
            {37264,24.41748508},
            {37261,24.359715},
            {37258,24.30194493},
            {37255,24.24417485},
            {37251,24.16714808},
            {37248,24.10937801},
            {37245,24.05160793},
            {37242,23.99383786},
            {37242,23.99383786},
            {37236,23.87829771},
            {37236,23.87829771},
            {37233,23.82052763},
            {37230,23.76275756},
            {37227,23.70498748},
            {37224,23.64721741},
            {37220,23.57019064},
            {37217,23.51242057},
            {37214,23.45465049},
            {37211,23.39688042},
            {37208,23.33911034},
            {37205,23.28134027},
            {37202,23.22357019},
            {37199,23.16580012},
            {37199,23.16580012},
            {37189,22.9732332},
            {37189,22.9732332},
            {37183,22.85769305},
            {37183,22.85769305},
            {37177,22.7421529},
            {37177,22.7421529},
            {37174,22.68438282},
            {37171,22.62661275},
            {37168,22.56884267},
            {37165,22.5110726},
            {37162,22.45330252},
            {37162,22.45330252},
            {37158,22.37627576},
            {37155,22.31850568},
            {37152,22.26073561},
            {37149,22.20296553},
            {37146,22.14519546},
            {37143,22.08742538},
            {37140,22.02965531},
            {37140,22.02965531},
            {37134,21.91411516},
            {37134,21.91411516},
            {37131,21.85634508},
            {37127,21.77931831},
            {37124,21.72154824},
            {37121,21.66377816},
            {37118,21.60600809},
            {37115,21.54823801},
            {37112,21.49046794},
            {37109,21.43269786},
            {37109,21.43269786},
            {37103,21.31715771},
            {37103,21.31715771},
            {37100,21.25938764},
            {37096,21.18236087},
            {37093,21.1245908},
            {37090,21.06682072},
            {37090,21.06682072},
            {37087,21.00905065},
            {37084,20.95128057},
            {37081,20.89351049},
            {37078,20.83574042},
            {37075,20.77797034},
            {37072,20.72020027},
            {37072,20.72020027},
            {37065,20.58540343},
            {37065,20.58540343},
            {37062,20.52763335},
            {37059,20.46986328},
            {37059,20.46986328},
            {37053,20.35432313},
            {37053,20.35432313},
            {37050,20.29655305},
            {37047,20.23878298},
            {37044,20.1810129},
            {37041,20.12324283},
            {37038,20.06547275},
            {37034,19.98844598},
            {37034,19.98844598},
            {37028,19.87290583},
            {37028,19.87290583},
            {37025,19.81513576},
            {37022,19.75736568},
            {37019,19.69959561},
            {37016,19.64182553},
            {37013,19.58405546},
            {37010,19.52628538},
            {37007,19.46851531},
            {37003,19.39148854},
            {37003,19.39148854},
            {36997,19.27594839},
            {36997,19.27594839},
            {36994,19.21817832},
            {36991,19.16040824},
            {36988,19.10263817},
            {36985,19.04486809},
            {36985,19.04486809},
            {36979,18.92932794},
            {36979,18.92932794},
            {36976,18.87155787},
            {36972,18.7945311},
            {36969,18.73676102},
            {36963,18.62122087},
            {36960,18.5634508},
            {36960,18.5634508},
            {36957,18.50568072},
            {36954,18.44791065},
            {36951,18.39014057},
            {36948,18.3323705},
            {36945,18.27460042},
            {36945,18.27460042},
            {36941,18.19757366},
            {36938,18.13980358},
            {36935,18.08203351},
            {36932,18.02426343},
            {36932,18.02426343},
            {36929,17.96649336},
            {36926,17.90872328},
            {36923,17.85095321},
            {36920,17.79318313},
            {36917,17.73541306},
            {36917,17.73541306},
            {36914,17.67764298},
            {36910,17.60061621},
            {36907,17.54284614},
            {36907,17.54284614},
            {36904,17.48507606},
            {36901,17.42730599},
            {36898,17.36953591},
            {36895,17.31176584},
            {36895,17.31176584},
            {36892,17.25399576},
            {36889,17.19622569},
            {36889,17.19622569},
            {36886,17.13845561},
            {36883,17.08068554},
            {36879,17.00365877},
            {36876,16.9458887},
            {36876,16.9458887},
            {36873,16.88811862},
            {36870,16.83034855},
            {36870,16.83034855},
            {36864,16.7148084},
            {36864,16.7148084},
            {36861,16.65703832},
            {36858,16.59926825},
            {36858,16.59926825},
            {36855,16.54149817},
            {36852,16.4837281},
            {36848,16.40670133},
            {36845,16.34893125},
            {36845,16.34893125},
            {36842,16.29116118},
            {36839,16.2333911},
            {36839,16.2333911},
            {36836,16.17562103},
            {36833,16.11785095},
            {36833,16.11785095},
            {36830,16.06008088},
            {36827,16.0023108},
            {36824,15.94454073},
            {36824,15.94454073},
            {36821,15.88677065},
            {36821,15.88677065},
            {36817,15.80974389},
            {36814,15.75197381},
            {36811,15.69420374},
            {36808,15.63643366},
            {36808,15.63643366},
            {36805,15.57866359},
            {36805,15.57866359},
            {36802,15.52089351},
            {36799,15.46312344},
            {36796,15.40535336},
            {36796,15.40535336},
            {36793,15.34758329},
            {36790,15.28981321},
            {36790,15.28981321},
            {36786,15.21278644},
            {36783,15.15501637},
            {36783,15.15501637},
            {36780,15.09724629},
            {36777,15.03947622},
            {36777,15.03947622},
            {36774,14.98170614},
            {36771,14.92393607},
            {36771,14.92393607},
            {36771,14.92393607},
            {36768,14.86616599},
            {36765,14.80839592},
            {36762,14.75062584},
            {36762,14.75062584},
            {36759,14.69285577},
            {36755,14.615829},
            {36755,14.615829},
            {36752,14.55805893},
            {36752,14.55805893},
            {36749,14.50028885},
            {36746,14.44251878},
            {36746,14.44251878},
            {36743,14.3847487},
            {36737,14.26920855},
            {36737,14.26920855},
            {36734,14.21143847},
            {36734,14.21143847},
            {36731,14.1536684},
            {36728,14.09589832},
            {36728,14.09589832},
            {36724,14.01887156},
            {36724,14.01887156},
            {36721,13.96110148},
            {36718,13.90333141},
            {36715,13.84556133},
            {36715,13.84556133},
            {36712,13.78779126},
            {36709,13.73002118},
            {36709,13.73002118},
            {36706,13.67225111},
            {36706,13.67225111},
            {36703,13.61448103},
            {36700,13.55671096},
            {36700,13.55671096},
            {36697,13.49894088},
            {36693,13.42191412},
            {36693,13.42191412},
            {36690,13.36414404},
            {36687,13.30637396},
            {36687,13.30637396},
            {36684,13.24860389},
            {36684,13.24860389},
            {36681,13.19083381},
            {36681,13.19083381},
            {36675,13.07529366},
            {36675,13.07529366},
            {36675,13.07529366},
            {36672,13.01752359},
            {36669,12.95975351},
            {36669,12.95975351},
            {36666,12.90198344},
            {36662,12.82495667},
            {36662,12.82495667},
            {36659,12.7671866},
            {36656,12.70941652},
            {36656,12.70941652},
            {36653,12.65164645},
            {36650,12.59387637},
            {36650,12.59387637},
            {36647,12.5361063},
            {36644,12.47833622},
            {36644,12.47833622},
            {36641,12.42056615},
            {36638,12.36279607},
            {36638,12.36279607},
            {36635,12.305026},
            {36631,12.22799923},
            {36631,12.22799923},
            {36628,12.17022915},
            {36625,12.11245908},
            {36625,12.11245908},
            {36622,12.054689},
            {36622,12.054689},
            {36619,11.99691893},
            {36619,11.99691893},
            {36616,11.93914885},
            {36613,11.88137878},
            {36613,11.88137878},
            {36610,11.8236087},
            {36607,11.76583863},
            {36607,11.76583863},
            {36604,11.70806855},
            {36600,11.63104179},
            {36600,11.63104179},
            {36597,11.57327171},
            {36594,11.51550164},
            {36594,11.51550164},
            {36591,11.45773156},
            {36588,11.39996149},
            {36588,11.39996149},
            {36585,11.34219141},
            {36582,11.28442134},
            {36582,11.28442134},
            {36579,11.22665126},
            {36576,11.16888119},
            {36576,11.16888119},
            {36573,11.11111111},
            {36569,11.03408434},
            {36569,11.03408434},
            {36566,10.97631427},
            {36563,10.91854419},
            {36563,10.91854419},
            {36560,10.86077412},
            {36557,10.80300404},
            {36557,10.80300404},
            {36554,10.74523397},
            {36551,10.68746389},
            {36548,10.62969382},
            {36548,10.62969382},
            {36545,10.57192374},
            {36542,10.51415367},
            {36538,10.4371269},
            {36538,10.4371269},
            {36535,10.37935683},
            {36532,10.32158675},
            {36532,10.32158675},
            {36529,10.26381668},
            {36526,10.2060466},
            {36523,10.14827653},
            {36523,10.14827653},
            {36520,10.09050645},
            {36517,10.03273638},
            {36511,9.917196226},
            {36511,9.917196226},
            {36507,9.840169459},
            {36504,9.782399384},
            {36501,9.724629309},
            {36498,9.666859234},
            {36498,9.666859234},
            {36495,9.609089158},
            {36492,9.551319083},
            {36489,9.493549008},
            {36489,9.493549008},
            {36486,9.435778933},
            {36483,9.378008858},
            {36480,9.320238783},
            {36476,9.243212016},
            {36473,9.185441941},
            {36473,9.185441941},
            {36470,9.127671866},
            {36467,9.069901791},
            {36464,9.012131716},
            {36461,8.954361641},
            {36458,8.896591566},
            {36458,8.896591566},
            {36455,8.83882149},
            {36452,8.781051415},
            {36449,8.72328134},
            {36445,8.646254573},
            {36442,8.588484498},
            {36439,8.530714423},
            {36439,8.530714423},
            {36436,8.472944348},
            {36430,8.357404198},
            {36430,8.357404198},
            {36427,8.299634123},
            {36424,8.241864048},
            {36421,8.184093973},
            {36418,8.126323898},
            {36418,8.126323898},
            {36414,8.049297131},
            {36411,7.991527056},
            {36408,7.933756981},
            {36408,7.933756981},
            {36405,7.875986905},
            {36402,7.81821683},
            {36399,7.760446755},
            {36396,7.70267668},
            {36393,7.644906605},
            {36390,7.58713653},
            {36387,7.529366455},
            {36387,7.529366455},
            {36383,7.452339688},
            {36380,7.394569613},
            {36377,7.336799538},
            {36374,7.279029463},
            {36371,7.221259388},
            {36368,7.163489313},
            {36365,7.105719237},
            {36362,7.047949162},
            {36359,6.990179087},
            {36356,6.932409012},
            {36352,6.855382245},
            {36349,6.79761217},
            {36346,6.739842095},
            {36343,6.68207202},
            {36340,6.624301945},
            {36337,6.56653187},
            {36331,6.45099172},
            {36331,6.45099172},
            {36325,6.335451569},
            {36325,6.335451569},
            {36318,6.200654728},
            {36315,6.142884652},
            {36312,6.085114577},
            {36309,6.027344502},
            {36306,5.969574427},
            {36300,5.854034277},
            {36297,5.796264202},
            {36294,5.738494127},
            {36290,5.66146736},
            {36284,5.54592721},
            {36278,5.43038706},
            {36275,5.372616984},
            {36272,5.314846909},
            {36269,5.257076834},
            {36263,5.141536684},
            {36259,5.064509917},
            {36256,5.006739842},
            {36253,4.948969767},
            {36247,4.833429617},
            {36244,4.775659542},
            {36241,4.717889467},
            {36235,4.602349316},
            {36232,4.544579241},
            {36228,4.467552474},
            {36222,4.352012324},
            {36219,4.294242249},
            {36216,4.236472174},
            {36210,4.120932024},
            {36207,4.063161949},
            {36201,3.947621799},
            {36197,3.870595032},
            {36191,3.755054882},
            {36188,3.697284806},
            {36185,3.639514731},
            {36179,3.523974581},
            {36176,3.466204506},
            {36170,3.350664356},
            {36166,3.273637589},
            {36160,3.158097439},
            {36154,3.042557289},
            {36151,2.984787214},
            {36148,2.927017138},
            {36142,2.811476988},
            {36139,2.753706913},
            {36132,2.618910071},
            {36126,2.503369921},
            {36123,2.445599846},
            {36117,2.330059696},
            {36114,2.272289621},
            {36111,2.214519546},
            {36104,2.079722704},
            {36098,1.964182553},
            {36095,1.906412478},
            {36089,1.790872328},
            {36083,1.675332178},
            {36080,1.617562103},
            {36073,1.482765261},
            {36067,1.367225111},
            {36058,1.193914885},
            {36055,1.13614481},
            {36049,1.02060466},
            {36046,0.962834585},
            {36036,0.770267668},
            {36033,0.712497593},
            {36027,0.596957443},
            {36021,0.481417293},
            {36018,0.423647217},
            {36011,0.288850376},
            {36005,0.173310225},
            {36002,0.11554015},
            {35996,0.10000000}
    };


        if(ele > FULL)
            return 100.0;

        if(ele < EMPTY && ele > 1)
            return 0.0;

        if (ele <= 1 && ele > 0){
            return  ele*100;
        }

        for(int i = 0; i < data.length; i++)
        {
            if(ele > data[i][0])
            {
                return data[i>=1?i -1:i][1];
            }
        }




        return 0;



    }










    /**
     * 通用提示框
     *
     * @param mContext
     * @param titleResId
     * @param msgResId
     * @param countDownSeconds
     */
    public static void showNotifyDialog(Context mContext, int titleResId, int msgResId, int countDownSeconds, CommCallback callback) {
        showNotifyDialog(mContext, titleResId, msgResId, 0, 0, null, null, countDownSeconds, callback);
    }

    /**
     * @param mContext
     * @param titleResId
     * @param msgResId
     * @param positiveResId
     * @param negativeResId
     * @param positiveListener 可为null，为null时自动new一个空的listener
     * @param negativeListener 可为null，为null时自动new一个空的listener
     * @param countDownSeconds 不使用时设置为0
     * @param callback         countDownSeconds大于0时才会执行
     */
    public static void showNotifyDialog(Context mContext, int titleResId, int msgResId,
                                        int positiveResId, int negativeResId,
                                        DialogInterface.OnClickListener positiveListener, DialogInterface.OnClickListener negativeListener,
                                        int countDownSeconds, CommCallback callback) {
        showNotifyDialog(mContext, mContext.getString(titleResId), mContext.getString(msgResId),
                positiveResId == 0 ? Constants.DEFAULT_BLANK : mContext.getString(positiveResId),
                negativeResId == 0 ? Constants.DEFAULT_BLANK : mContext.getString(negativeResId),
                positiveListener, negativeListener, countDownSeconds, callback);
    }

    public static void showNotifyDialog(Context mContext, String titleText, String msgText,
                                        String positiveBtText, String negativeBtText,
                                        DialogInterface.OnClickListener positiveListener, DialogInterface.OnClickListener negativeListener,
                                        int countDownSeconds, final CommCallback callback) {
        final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext);
        View view = LayoutInflater.from(mContext).inflate(R.layout.remind_watch, null);
        TextView title = (TextView) view.findViewById(R.id.title);
        TextView msg = (TextView) view.findViewById(R.id.message);
        title.setText(titleText);
        msg.setText(msgText);
        dialogBuilder.setView(view);
        dialogBuilder.setCancelable(false);
        if (CommUtil.isNotBlank(positiveBtText)) {
            if (positiveListener == null) {
                positiveListener = new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                };
            }
            dialogBuilder.setPositiveButton(positiveBtText, positiveListener);
        }
        if (CommUtil.isNotBlank(negativeBtText)) {
            if (negativeListener == null) {
                negativeListener = new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                };
            }
            dialogBuilder.setNegativeButton(negativeBtText, negativeListener);
        }
        if (countDownSeconds > 0) {
            dialogBuilder.setCancelable(true);
            CommUtil.delayExecute(countDownSeconds * 1000, new CommCallback() {
                @Override
                public void execute() {
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                    if (callback != null) {
                        callback.execute();
                    }
                }
            });
        }
        dialog = dialogBuilder.create();
        dialog.show();
    }

    /**
     * 加密
     *
     * @param str
     * @return
     */
    public static String enctype(String str) {
        List<String> keys = DigestUtils.appKeysList;
        List<Integer> inKeys = new ArrayList<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 3; i++) {
            int x = rand.nextInt(CommUtil.min(99, keys.size()));
            if (x < 10) {
                sb.append('0');
            }
            sb.append(x);
            inKeys.add(CommUtil.toInteger(keys.get(x)));
        }
        sb.append(DigestUtils.encrypt(str, inKeys));
        return sb.toString();
    }

    /**
     * 解密
     *
     * @param str
     * @return
     */
    public static String decrypt(String str) {
        List<Integer> keys = new ArrayList<>(3);
        for (int i = 0; i < 3; i++) {
            int idx = CommUtil.toInteger(str.substring(i * 2, (i + 1) * 2));
            keys.add(CommUtil.toInteger(DigestUtils.appKeysList.get(idx)));
        }
        return DigestUtils.decrypt(str.substring(6), keys);
    }

    public static ArrayList<String> genTimezones() {
        ArrayList<String> timeZoneIds = new ArrayList<>(25);
        for (int i = -12; i <= 12; i++) {
            StringBuilder sb = new StringBuilder(Constants.TIME_ZONE_PREFIX);
            if (i < 0) {
                sb.append('-');
            } else if (i > 0) {
                sb.append('+');
            }
            if (i < 10 && i > -10) {
                sb.append('0');
            }
            sb.append(i > 0 ? i : -i);
            sb.append(":00");
            if (i < 0 && i > -12) {
                String str = sb.toString();
                timeZoneIds.add(sb.replace(sb.length() - 2, sb.length() - 1, "3").toString());
                timeZoneIds.add(str);
            } else if (i > 0 && i < 12) {
                timeZoneIds.add(sb.toString());
                timeZoneIds.add(sb.replace(sb.length() - 2, sb.length() - 1, "3").toString());
            } else if (i == 12 || i == -12) {
                timeZoneIds.add(sb.toString());
            } else if (i == 0) {
                String str = sb.toString();
                timeZoneIds.add(sb.insert(4, '-').replace(sb.length() - 2, sb.length() - 1, "3").toString());
                timeZoneIds.add(str);
                timeZoneIds.add(sb.replace(4, 5, "+").toString());
            }
        }
        return timeZoneIds;
    }

    public static String formatTimezoneOffset(float offset) {
        StringBuilder sb = new StringBuilder(Constants.TIME_ZONE_PREFIX);
        int off = (int) offset;
        if (off < 0) {
            sb.append('-');
        } else if (off > 0) {
            sb.append('+');
        }
        if (off > -10 && off < 10) {
            sb.append('0');
        }
        sb.append(off > 0 ? off : -off).append(':');
        if (offset - off != 0.0) {
            sb.append('3');
        } else {
            sb.append('0');
        }
        sb.append('0');
        return sb.toString();
    }

    public static float convertTimezoneToOffset(String off) {
        return Float.parseFloat(off.replace(Constants.TIME_ZONE_PREFIX, "").replace(":", ".").replace("30", "5"));
    }

    /**
     * 隐藏软键盘
     *
     * @param activity 上下文Activity环境
     * @param view     焦点所在控件
     */
    public static void hideInputBoard(Activity activity, View view) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        if (view == null) {
            IBinder binder = activity.getCurrentFocus() == null ? new Binder() : activity.getCurrentFocus().getApplicationWindowToken();
            imm.hideSoftInputFromWindow(binder, InputMethodManager.HIDE_NOT_ALWAYS);
        } else {
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

    /**
     * 显示软键盘
     *
     * @param activity 上下文Activity环境
     * @param view     焦点所在控件
     */
    public static void showInputBoard(Activity activity, View view) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        if (view == null) {
            IBinder binder = activity.getCurrentFocus() == null ? new Binder() : activity.getCurrentFocus().getApplicationWindowToken();
            imm.showSoftInputFromInputMethod(binder, InputMethodManager.SHOW_FORCED);
        } else if (imm != null) {
            view.requestFocus();
            view.requestFocusFromTouch();
            imm.showSoftInput(view, 0);
            imm.showSoftInputFromInputMethod(view.getWindowToken(), InputMethodManager.SHOW_FORCED);
        }
    }

    /**
     * Tools send command in chatActivity
     *
     * @param imei    Target IMEI.
     * @param type    CMD type.
     * @param msgCont Content displaying chat window.
     * @param cont    CMD content.
     */
    public static void sendCommand(String imei, String type, String msgCont, String cont) {
        ChatMsg chatMsg = new ChatMsg();
        chatMsg.setIsSend(false);
        chatMsg.setImei(imei);
        chatMsg.setType(ContType.CMD.getType());
        chatMsg.setTermType(Session.getInstance().getMapEntityByImei(imei).getTermType().getType());
        chatMsg.setUserId(Session.getInstance().getLoginedUserId());
        chatMsg.setTime(System.currentTimeMillis());
        chatMsg.setContent(msgCont);

        AppContext.getEventBus().post(chatMsg, Constants.EVENT_TAG_CHAT_DISPLAYMSG);
        try {
            AppContext.db.saveBindingId(chatMsg);
        } catch (Exception e) {
            Log.e(Constants.TAG, "保存聊天信息到数据库失败！", e);
        }

        if (type != null) {
            ChatMsg cmdMsg = chatMsg.clone();
            Cmd cmd = new Cmd(type, cont, imei);
            cmdMsg.setContent(cmd.toJson());
            AppContext.getEventBus().post(cmdMsg, Constants.EVENT_TAG_CHAT_SEND);
        }
    }

    /**
     * 获取当前屏幕旋转角度
     *
     * @param context
     * @return 0表示是竖屏; 90表示是左横屏; 180表示是反向竖屏; 270表示是右横屏
     */
    public static float getScreenRotationOnPhone(Context context) {
        final Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        switch (display.getRotation()) {
            case Surface.ROTATION_0:
                return 0;
            case Surface.ROTATION_90:
                return 90;
            case Surface.ROTATION_180:
                return 180;
            case Surface.ROTATION_270:
                return -90;
        }
        return 0;
    }

    public static void playSoundAndVibrate(Context context) {
        Uri uri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION);
        playSoundAndVibrate(context, uri);
    }

    public static void playSoundAndVibrate(Context context, Uri uri) {
        if (!isPlaying) {
            try {
                SharedPreferences sp = Utils.getPreferences(context);
                if (sp.getBoolean(Constants.MSG_VOICE, true)) {
                    //获取系统默认铃声的Uri
                    Utils.playShortSound(context, uri);
                }

                if (sp.getBoolean(Constants.MSG_VIBRATE, true)) {
                    //zwd注释震动
//                    Vibrator vibrator = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);
//                    //设置震动时长，停50毫秒，震动100毫秒，震动两次
//                    vibrator.vibrate(new long[]{100, 300}, -1);
                }
            } catch (Exception e) {
                Log.e(Utils.class.getName(), "Play sound failed!", e);
            }
        }
    }
}
